<template>
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">
                        <div>
                            <form class="form-inline" onsubmit="return false;">

                                <div class="row">
                                    <div class="input-daterange input-group" style="width:30%;margin-left: 8px;">
                                        <el-date-picker
                                                v-model="startTime"
                                                type="date"
                                                format="yyyy-MM-dd"
                                                @change="getStartTime"
                                                placeholder="选择日期">
                                        </el-date-picker>
                                        <span class="input-group-addon"><i class="mdi mdi-chevron-right"></i></span>
                                        <el-date-picker
                                                v-model="endTime"
                                                type="date"
                                                @change="getEndTime"
                                                format="yyyy-MM-dd"
                                                placeholder="选择日期">
                                        </el-date-picker>
                                    </div>
                                    <div class="form-group">
                                        <el-select v-model="isPay" placeholder="提现状态">
                                            <el-option
                                                    v-for="item in options"
                                                    :key="item.value"
                                                    :label="item.label"
                                                    :value="item.value">
                                            </el-option>
                                        </el-select>
                                    </div>
                                </div>

                                <div class="row" style="margin-top: 10px;">

                                    <div class="form-group" style="margin-left: 7px;">
                                        <input class="form-control" type="text" placeholder="用户名" v-model="nickName">
                                    </div>
                                    <div class="form-group" style="margin-left: 7px;">
                                        <input class="form-control" type="text" placeholder="订单号" v-model="orderSn">
                                    </div>

                                    <div class="form-group" style="float:right;margin-right:100px;">
                                        <button class="btn btn-success" type="submit" v-on:click="search()">筛选</button>
                                    </div>
                                </div>


                            </form>
                        </div>
                        <div class="table-responsive" style="width: 100%;margin-top: 20px;" v-loading="loading">
                            <el-table
                                    :data="list"
                                    style="width: 100%"
                            >
                                <el-table-column
                                        prop="order_sn"
                                        label="订单编号"
                                        align="center"
                                        width="180">
                                </el-table-column>
                                <el-table-column
                                        prop="service_name"
                                        label="会员类型"
                                        align="center"
                                        width="68">
                                </el-table-column>
                                <el-table-column
                                        align="center"
                                        prop="price"
                                        label="订单金额"
                                        width="68">
                                </el-table-column>
                                <el-table-column
                                        align="center"
                                        prop="direct_commission"
                                        label="直推佣金"
                                        width="68">
                                </el-table-column>
                                <el-table-column
                                        align="center"
                                        prop="disseminate_commission"
                                        label="间推佣金"
                                        width="68">
                                </el-table-column>
                                <el-table-column
                                        prop="statusText"
                                        label="订单状态"
                                        align="center"
                                        width="68">
                                </el-table-column>
                                <el-table-column
                                        prop="nick_name"
                                        label="下单用户"
                                        width="68">
                                </el-table-column>
                                <el-table-column
                                        prop="recommendName"
                                        label="直接代理"
                                        align="center"
                                        width="68">
                                </el-table-column>
                                <el-table-column
                                        prop="mobile"
                                        align="center"
                                        label="手机号"
                                        width="100">
                                </el-table-column>
                                <el-table-column
                                        prop="created_at"
                                        align="center"
                                        label="下单时间"
                                        width="150">
                                </el-table-column>
                                <el-table-column
                                        label="操作"
                                        align="center"
                                        width="170"
                                >
                                    <template slot-scope="scope">
                                        <el-button size="mini" type="success" @click="handleStatus(scope.row._id,1)"
                                                   v-if="scope.row.status===8">退款关闭
                                        </el-button>
                                    </template>

                                </el-table-column>
                            </el-table>

                            <nav style="margin-top: 20px">
                                <el-pagination
                                        layout="total, sizes, prev, pager, next"
                                        :total="total"
                                        :hide-on-single-page="pageActive"
                                        @size-change="handleSizeChange"
                                        :page-size="pageSize"
                                        :current-page="currentPage"
                                        :page-sizes="[10, 20, 30, 40]"
                                        @current-change="handleCurrentChange"
                                >
                                </el-pagination>
                            </nav>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "OrderComponent",
        data() {
            return {
                startTime: '',
                endTime: '',
                pageActive: true,
                list: [],
                pageSize: 10,
                total: 0,
                currentPage: 1,
                loading: true,
                isPay: -1,
                nickName: '',
                orderSn: '',
                options: [{
                    value: -1,
                    label: '全部'
                }, {
                    value: 1,
                    label: '已付款'
                }, {
                    value: 0,
                    label: '未付款'
                }],
            }
        },
        methods: {
            handleCurrentChange: function (val) {
                this.currentPage = val;
                this.search();
            },
            handleSizeChange: function (pageSize) {
                this.pageSize = pageSize;
                this.search();
            },
            search: function () {
                let self = this;
                let uri = 'order/post-list';
                self.loading = true;

                let postData = {
                    startTime: self.startTime,
                    endTime: self.endTime,
                    page: self.currentPage,
                    limit: self.pageSize,
                    is_pay: self.isPay,
                    nickname: self.nickName,
                    order_sn: self.orderSn,
                };

                axios.post(uri, postData).then(function (result) {
                    self.total = result.orders.total;
                    if (self.total > 0) {
                        self.pageActive = false;
                    } else {
                        self.pageActive = true;
                    }
                    self.list = result.orders.data;
                    self.loading = false;
                }).catch(function (error) {
                    self.loading = false;
                });
            },
            getStartTime(date) {
                this.startTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
            },
            getEndTime: function (date) {
                this.endTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
            },
        },
        mounted() {
            this.search();
        }
    }
</script>

<style scoped>

</style>
